import sys

class Solution(object):
    def findMin(self, nums):
        begin = 0
        end = len(nums)-1
        while begin<end:
            mid = (begin+end)//2
            if nums[begin]==nums[end]:
                if nums[mid]>nums[begin]:
                    begin=mid+1
                elif nums[mid]<nums[begin]:
                    end=mid
                else:
                    minElem = sys.maxsize
                    if begin<mid:
                        minElem = min(minElem, self.findMin(nums[begin:mid]))
                    if mid<end:
                        minElem = min(minElem, self.findMin(nums[mid+1:end+1]))
                    return minElem
            elif nums[begin]>nums[end]:
                if nums[mid]>=nums[begin]:
                    begin=mid+1
                else:
                    end=mid
            else:
                return nums[begin]
        return nums[begin]

print(Solution().findMin([3,3,1,3]))